﻿// Copyright (c) Vitaly Kamiansky. All rights reserved. 
// See License.txt in the project root.

using System;
using System.ComponentModel;

namespace Property.Workers
{
    public class ForegroundWorker : Worker
    {
        protected ForegroundWorker()
        { }

        //=//

        public override bool IsBusy { get { return false; } }

        public override void RunWorkerAsync()
        {
            OnDoWork();
        }

        private void OnDoWork()
        {
            try
            {
                var workResult = new DoWorkEventArgs(null);
                OnDoWork(workResult);
                OnRunWorkerCompleted(new RunWorkerCompletedEventArgs(workResult.Result, null, false));
            }
            catch (Exception e)
            {
                OnRunWorkerCompleted(new RunWorkerCompletedEventArgs(null, e, false));
            }
        }
    }
}
